package spilder;


import com.huaban.analysis.jieba.JiebaSegmenter;
import org.ansj.domain.Result;
import org.ansj.domain.Term;
import org.ansj.splitWord.analysis.ToAnalysis;
import org.json.JSONObject;
import org.junit.Test;

import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Utils {
   public static  Object getObject(String str){
       JSONObject jsonObj = new JSONObject(str);
       return jsonObj;
   }

   public static void toAnalysis(String str) throws IOException {
       List<String> strList = new ArrayList();
       Result parse = ToAnalysis.parse(str);
       for (Term term : parse) {
           String realName = term.getRealName();
            strList.add(realName);
       }
        saveResult(strList);
   }

    private static void saveResult(List<String> strList) throws IOException {
        FileWriter fw = new FileWriter("e:/contents.txt",true);
        for (String s : strList) {
            if(s.length()==1)
                continue;
            fw.write(s+",");
        }
        fw.close();
    }
}
